class RandomizedSet {
public:
    RandomizedSet()
    {
        srand((unsigned)time(NULL));
    }

    bool insert(int val)
    {
        if (mp.count(val)) return false;
        int index = nums.size();
        nums.emplace_back(val);
        mp[val] = index;
        return true;
    }

    bool remove(int val)
    {
        if (!mp.count(val)) return false;
        int index = mp[val];
        int last = nums.back();
        nums[index] = last;
        mp[last] = index;
        nums.pop_back();
        mp.erase(val);
        return true;
    }

    int getRandom()
    {
        int index = rand() % nums.size();
        return nums[index];
    }
private:
    vector<int> nums;
    unordered_map<int, int> mp;
};